<?php
class ContactController extends Zendme_Controller_Action
{
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	protected $_paginator = array(
									'itemCountPerPage' => 10,
									'pageRange' => 3,
								  ); 
	protected $_namespace;
	
	public function init(){
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		
		//Duong dan cua Controller
		$this->_currentController = '/' . $this->_arrParam['module'] 
									 . '/' . $this->_arrParam['controller'];
		
		//Duong dan cua Action chinh		
		$this->_actionMain = '/' . $this->_arrParam['module'] 
							 . '/' . $this->_arrParam['controller']	. '/index';	
							 
		//Luu cac du lieu filter vao SESSION
		//Dat ten SESSION
		$this->_namespace = $this->_arrParam['module'] . '-' . $this->_arrParam['controller'];
		
		$ssFilter = new Zend_Session_Namespace($this->_namespace);
		
		if(empty($ssFilter->col)){
			$ssFilter->lang 		= '';
		}
		$this->_arrParam['ssFilter']['lang'] 		= $this->_arrParam['lang'];	
		
		$info = new Zendme_System_Info();
		$language = $info->getLanguage('admin');
		if(empty($language)){
			$language = 'vi';
		}
		$translate = array(
							'adapter' => 'tmx',
							'content' => LANG_PATH . '/' . $language . '/admin/menu.tmx',
							'locale' => $language,
							);
		$translate = new Zend_Translate($translate);
		Zend_Registry::set('Zend_Translate', $translate);
		
		//Truyen ra view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
		
		$template_path = TEMPLATE_PATH . "/admin/system";
		$this->loadTemplate($template_path,'template.ini','template');
	}
	
	public function editAction()
	{
		$this->view->Title = 'CONTACT';
		$this->view->headTitle($this->view->Title,true);
		
		$mdl=new Zendme_Models_Contact();
		
		if($this->_request->isPost())
		{
			$mdl->saveItem($this->_arrParam,array('task'=>'admin-edit'));
		}
		
		$item=$mdl->getItem(null,array('task'=>'admin-edit'));
		$this->view->item=$item;
		
//		if($this->_request->isPost()){
//			$validator = new Default_Form_ValidateContact($this->_arrParam);
//			if($validator->isError() == true){
//				$this->view->errors 	= $validator->getMessageError();
//				$this->view->Item		= $validator->getData();
//			}else{
//				$arrParam = $validator->getData(array('upload'=>true));
//				$mdl	->saveItem($arrParam,array('task'=>'admin-edit'));
//				$this->_redirect($this->_arrParam['module'].'/'.$this->_arrParam['controller'].'/'
//								.$this->_arrParam['action'].'/id/'.$this->_arrParam['id']);
//			}
//		}
		
	}
}